home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Filling Shapes with a Gradient Brush / Creating a Path Gradient / Customizing a Path Gradient / APP1 / GDITEST79.dpr
Encoding:
Text File  |  2003-10-15  |  3.1 KB  |  118 lines

  1. program GDITEST79;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10. Procedure OnPaint(DC: HDC);
  11. var
  12.   graphics : TGPGraphics;
  13.   path: TGPGraphicsPath;
  14.   pthGrBrush: TGPPathGradientBrush;
  15.   num: Integer;
  16. const
  17.   colors: array[0..0] of TGPColor = (aclBlue);
  18. begin
  19.   graphics := TGPGraphics.Create(DC);
  20.  
  21.   // Create a path that consists of a single ellipse.
  22.   path:= TGPGraphicsPath.Create;
  23.   path.AddEllipse(0, 0, 200, 100);
  24.  
  25.   // Create a path gradient brush based on the elliptical path.
  26.   pthGrBrush:= TGPPathGradientBrush.Create(path);
  27.   pthGrBrush.SetGammaCorrection(TRUE);
  28.  
  29.   // Set the color along the entire boundary to blue.
  30.   num := 1;
  31.   pthGrBrush.SetSurroundColors(@colors, num);
  32.  
  33.   // Set the center color to aqua.
  34.   pthGrBrush.SetCenterColor(aclAqua);
  35.  
  36.   // Use the path gradient brush to fill the ellipse.
  37.   graphics.FillPath(pthGrBrush, path);
  38.  
  39.   // Set the focus scales for the path gradient brush.
  40.   pthGrBrush.SetFocusScales(0.3, 0.8);
  41.  
  42.   // Use the path gradient brush to fill the ellipse again.
  43.   // Show this filled ellipse to the right of the first filled ellipse.
  44.   graphics.TranslateTransform(220.0, 0.0);
  45.   graphics.FillPath(pthGrBrush, path);
  46.  
  47.   path.Free;
  48.   pthGrBrush.Free;
  49.   graphics.Free;
  50. end;
  51.  
  52.  
  53. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  54. var
  55.   Handle: HDC;
  56.   ps: PAINTSTRUCT;
  57. begin
  58.   case message of
  59.     WM_PAINT:
  60.       begin
  61.         Handle := BeginPaint(Wnd, ps);
  62.         OnPaint(Handle);
  63.         EndPaint(Wnd, ps);
  64.         result := 0;
  65.       end;
  66.  
  67.     WM_DESTROY:
  68.       begin
  69.         PostQuitMessage(0);
  70.         result := 0;
  71.       end;
  72.  
  73.    else
  74.       result := DefWindowProc(Wnd, message, wParam, lParam);
  75.    end;
  76. end;
  77.  
  78. var
  79.   hWnd     : THandle;
  80.   Msg      : TMsg;
  81.   wndClass : TWndClass;
  82. begin
  83.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  84.    wndClass.lpfnWndProc    := @WndProc;
  85.    wndClass.cbClsExtra     := 0;
  86.    wndClass.cbWndExtra     := 0;
  87.    wndClass.hInstance      := hInstance;
  88.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  89.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  90.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  91.    wndClass.lpszMenuName   := nil;
  92.    wndClass.lpszClassName  := 'GettingStarted';
  93.  
  94.    RegisterClass(wndClass);
  95.  
  96.    hWnd := CreateWindow(
  97.       'GettingStarted',       // window class name
  98.       'Customizing a Path Gradient',       // window caption
  99.       WS_OVERLAPPEDWINDOW,    // window style
  100.       Integer(CW_USEDEFAULT), // initial x position
  101.       Integer(CW_USEDEFAULT), // initial y position
  102.       Integer(CW_USEDEFAULT), // initial x size
  103.       Integer(CW_USEDEFAULT), // initial y size
  104.       0,                      // parent window handle
  105.       0,                      // window menu handle
  106.       hInstance,              // program instance handle
  107.       nil);                   // creation parameters
  108.  
  109.    ShowWindow(hWnd, SW_SHOW);
  110.    UpdateWindow(hWnd);
  111.  
  112.    while(GetMessage(msg, 0, 0, 0)) do
  113.    begin
  114.       TranslateMessage(msg);
  115.       DispatchMessage(msg);
  116.    end;
  117. end.
  118.